Notebook 2 Making a library

Here we go through making a library from a annotations files. There are two main stages to making the library, creating it and then appending to the library.

If you have already added features to the files that the annotations point to, these will be automatically included in the library. It is therefore reccomended that you pass in “overwrite=False” to the method handler.add_features_to_seizure_library (as below).

Note: it is important the the timewindow parameter passed to the library is the same as the timewindow parameter passed to the add_predictions_features at the end of notebook 1.

Loading the pyecog module

The easiest place to place and run this notebook is from the pyecog directory downloaded from github, e.g. “pyecog-Development” as the pyecog module will be found in this folder. However, if you want to run the notebook from else where on your computer you first need to make sure that python can find the pyecog module using sys.path.append(). To do this modify and copy the following code into a cell and run it (shift+enter).

import sys
pyecog_path = 'home/jonathan/git_repos/pyecog' # replace this with the pyecog location
sys.path.append(pyecog_path)

If you are on windows you have to deal with the problem that backslashes in your paths are treated escape characters by python. Prefixing the string with ‘r’ prevents this.

pyecog_path_windows = r'home\jonathan\git_repos\pyecog' # replace this with the pyecog location
In [1]:
import sys
import os
import pandas as pd
In [2]:
# note if you are in the directory downloaded from github you do not have to run this cell
pyecog_path = '/home/jonathan/git_repos/pyecog'

# e.g. if on a windows computer
# pyecog_path = r'C:\Users\jonathan\Desktop\pyecog-Development'

sys.path.append(pyecog_path)
In [4]:
import pyecog as pg

pg # check the module is imported from where you expect
Out[4]:
<module 'pyecog' from '/home/jonathan/git_repos/pyecog/pyecog/__init__.py'>
In [6]:

Log of things added to library:

Note once you have ran code to make a library, it is a good idea to store a record of the files and folders used to create the the library. This will also allow you to recreate the library easily if you lose it! (or change the annotations).

annotations_path = r'C:\Users\wykeslab\Desktop\KA Annotations\AnnotationsOnly_T199.csv'
h5_folderpath    = r'C:\Users\wykeslab\Desktop\KA rats pilot study\H5_All'
handler.make_seizure_library(df = annotations_df,
                             file_dir=h5_folderpath,
                             timewindow=5,
                             seizure_library_name=seizure_lib_path)

handler.add_features_to_seizure_library(library_path=seizure_lib_path,
                                        overwrite=False)


# on march 2019 added these etc etc
annotations_path = r'C:\Users\wykeslab\Desktop\KA Annotations\AnnotationsOnly_T199.csv'
h5_folderpath    = r'C:\Users\wykeslab\Desktop\KA rats pilot study\H5_All'

handler.append_to_seizure_library(df = annotations_df,
                                 file_dir=h5_folderpath,
                                 timewindow=5,
                                 seizure_library_name=seizure_lib_path)
handler.add_features_to_seizure_library(library_path=seizure_lib_path,
                                        overwrite=False)

^^ place code once ran into this cell

1. Make library

  • Note you should run a ‘if exists check…’
In [ ]:
# the first set of annotations. make a brand new library

seizure_lib_path = 'test30' # filepath of new library (note also required for appending to library below)

annotations_path = r'C:\Users\wykeslab\Desktop\KA Annotations\AnnotationsOnly_T199.csv'
h5_folderpath    = r'C:\Users\wykeslab\Desktop\KA rats pilot study\H5_All'

handler.make_seizure_library(df = annotations_df,
                             file_dir = h5_folderpath,
                             timewindow = 5, # this sets the chunk size
                             seizure_library_name=seizure_lib_path)

handler.add_features_to_seizure_library(library_path=seizure_lib_path,
                                        timewindow = 5,
                                        overwrite=False)

2. Add to library

In [ ]:
# more annotations, add to existing library
annotations_path = r'C:\Users\wykeslab\Desktop\KA Annotations\AnnotationsOnly_T199.csv'
h5_folderpath    = r'C:\Users\wykeslab\Desktop\KA rats pilot study\H5_All'

In [ ]:
handler.append_to_seizure_library(df = annotations_df,
                                 file_dir= h5_folderpath,
                                 timewindow=5,
                                 seizure_library_name = seizure_lib_path)
In [ ]:
handler.add_features_to_seizure_library(library_path=seizure_lib_path,
                                        timewindow =5,
                                        overwrite=False)